//
//  MoreViewController.m
//  微blog
//
//  Created by Jorn.Wu on 15/8/19.
//  Copyright (c) 2015年 Jorn.Wu(jorn_wza@sina.com). All rights reserved.
//

#import "MoreViewController.h"
#import "MoreTableViewCell.h"
#import "MoreTableViewCellModel.h"
#import "MoreThemeListViewController.h"
#import "ThemeManager.h"

@interface MoreViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, copy) NSArray *cellModelAr;

@end

@implementation MoreViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self creatTableView];
    
}


/**
 * cellModelAr的get方法（懒加载数据）
 */
- (NSArray *)cellModelAr{
    
    if (!_cellModelAr) {
        
        ThemeManager *manager = [ThemeManager defualtManager];
#warning -------------detailText暂定
        MoreTableViewCellModel *model0 = [MoreTableViewCellModel modelWithText:@"主题选择"
                                                                    detailText:manager.themeName
                                                                 textColorName:@"More_Item_Text_color"
                                                                      iconName:@"more_icon_theme.png"
                                                            backgroudColorName:@"More_Item_color"];
        
        MoreTableViewCellModel *model1 = [MoreTableViewCellModel modelWithText:@"账户管理"
                                                                    detailText:nil
                                                                 textColorName:@"More_Item_Text_color"
                                                                      iconName:@"more_icon_account.png"
                                                            backgroudColorName:@"More_Item_color"];
        
        MoreTableViewCellModel *model2 = [MoreTableViewCellModel modelWithText:@"意见反馈"
                                                                    detailText:nil
                                                                 textColorName:@"More_Item_Text_color"
                                                                      iconName:@"more_icon_feedback.png"
                                                            backgroudColorName:@"More_Item_color"];
        
        MoreTableViewCellModel *model3 = [MoreTableViewCellModel modelWithText:@"注销登录"
                                                                    detailText:nil
                                                                 textColorName:@"More_Item_Text_color"
                                                                      iconName:nil
                                                            backgroudColorName:@"More_Item_color"];
        
        _cellModelAr = [NSArray arrayWithObjects:model0,model1,model2,model3, nil];
        
    }
    
    return _cellModelAr;
    
}


/**
 * 创建tabelView
 */
- (void)creatTableView{
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 49) style:UITableViewStyleGrouped];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    [self.view addSubview:_tableView];
}


/**
 * 返回节数
 */
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}


/**
 * 返回每节的cell个数
 */
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    switch (section) {
        case 0:
            return 2;
            break;
        case 1:
            return 1;
            break;
        default:
            return 1;
            break;
    };
}


/**
 * 创建cell，cell用自定义的cell类创建
 */
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *ID = @"MoreCell";
    MoreTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
#warning -----------style暂定
        cell = [[MoreTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    
    NSInteger section = indexPath.section;
    NSInteger row = indexPath.row;
    
    MoreTableViewCellModel *model = nil;
    if (section == 0) {
        model = self.cellModelAr[row];
    }
    
    if (section == 1) {
        model = self.cellModelAr[2];
    }
    
    if (section == 2) {
        model = self.cellModelAr[3];
    }
    
    cell.model = model;
    
    
    if (indexPath.section != 2) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    return cell;
}


/**
 * 选择某一行
 */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //消除cell选择痕迹
    [self performSelector:@selector(deselect) withObject:nil afterDelay:0.5f];
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        
        MoreThemeListViewController *themelistVC = [[MoreThemeListViewController alloc] init];
        [self.navigationController pushViewController:themelistVC animated:YES];
        
    }

}

- (void)deselect
{
    [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
}









- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
